package com.ihr360.commons.model.type;

public enum AccessPrivilege {
    /**
     * 拥有者
     */
    OWNER("拥有者"),
    /**
     * 可编辑
     */
    EDITOR("可编辑"),
    /**
     * 可读
     */
    READONLY("可读");


    AccessPrivilege(String title) {
        this.title = title;
    }

    private String title;

    public String getTitle() {
        return title;
    }
    public final static class Privilege {
        public final static int NONE = 0;
        public final static int OWNER = 1;
        public final static int EDITABLE = 2;
        public final static int READONLY = 4;
        public final static int COMPANY = 8;
        public final static int PUBLIC = 16;

    }

    public static AccessPrivilege getAccessPrivilege(Integer privilege) {
        if (privilege == null) {
            return null;
        }
        if (privilege == Privilege.OWNER) {
            return AccessPrivilege.OWNER;
        }
        if (privilege == Privilege.EDITABLE) {
            return AccessPrivilege.EDITOR;
        }
        if (privilege == Privilege.READONLY) {
            return AccessPrivilege.READONLY;
        }
        return null;
    }

    public static int getPrivilege(AccessPrivilege accessPrivilege) {
        if (accessPrivilege == AccessPrivilege.OWNER) {
            return Privilege.OWNER;
        }
        if (accessPrivilege == AccessPrivilege.EDITOR) {
            return Privilege.EDITABLE;
        }
        if (accessPrivilege == AccessPrivilege.READONLY) {
            return Privilege.READONLY;
        }
        return Privilege.NONE;
    }

}